package com.grgbanking.it.common.util;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;


/**
 * 日期处理基础类
 * @author pgwei
 *
 */
public class DateUtil {
	private static DateUtil common = new DateUtil();
	
	public static DateUtil getInstance(){
		return common;
	}
	
	/**
	 * 今天(年月日 时:分:秒)
	 * 
	 * @return String
	 */
	public String todayShort() {
		return this.today("yyyyMMdd HH:mm:ss");
	}
	/**
	 * 今天
	 * today
	 * 
	 * @param pattern
	 * @return 
	 * @exception 
	 * @since  1.0.0
	 */
	public String today(String pattern){
		return getFormat(pattern).format(new Date());
	}
	/**
	 * 昨天
	 * yesterday
	 * 
	 * @param pattern
	 * @return 
	 * @exception 
	 * @since  1.0.0
	 */
	public String yesterday(String pattern){
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.DATE, -1);
		return getFormat(pattern).format(calendar.getTime());
	}
	/**
	 * 获取格式化工具
	 * getFormat
	 * 
	 * @param pattern
	 * @return 
	 * @exception 
	 * @since  1.0.0
	 */
	private SimpleDateFormat getFormat(String pattern){
		return new SimpleDateFormat(pattern);
	}
	/**
	 * 明天的时间
	 * tomorrow
	 * 
	 * @return 
	 * @exception 
	 * @since  1.0.0
	 */
	public Timestamp tomorrow(){
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.DATE, 1);
		String time = getFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());
		return  Timestamp.valueOf(time);
	}
	/**
	 * 现在时间
	 * now
	 * 
	 * @return 
	 * @exception 
	 * @since  1.0.0
	 */
	public Timestamp now(){
		return new Timestamp(System.currentTimeMillis());
	}
}
